<template>
	<el-dialog width="500px" title="提现审核" :visible.sync="dialogVisible" :close-on-click-modal="false">
		<el-form ref="ruleForm" :model="form" label-width="100px">
			<el-form-item label="ID">
				<el-input v-model="editId" :rows="4" placeholder="备注" disabled />
			</el-form-item>
			<el-form-item label="审核状态">
				<el-select v-model="form.status" placeholder="请选择" @change="handleChange">
					<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="原因" prop="remark">
				<el-input v-model="form.remark" type="textarea" :rows="4" placeholder="备注" />
			</el-form-item>
		</el-form>
		<div slot="footer" class="dialog-footer">
			<el-button size="small" @click="dialogVisible = false">取 消</el-button>
			<el-button size="small" type="primary" @click="submit">确 定</el-button>
		</div>
	</el-dialog>
</template>

<script>
import { withdrawalPass, withdrawalRefuse } from '@/api/finance'
export default {
	props: {
		editId: {
			type: String,
			default: ''
		}
	},
	data() {
		return {
			form: {
				id: '',
				remark: '',
				status: ''
			},
			options: [{
				value: '1',
				label: '审核通过'
			}, {
				value: '2',
				label: '审核拒绝'
			}],
			value: '',
			dialogVisible: false
		}
	},
	methods: {
		handleChange(val) {
			this.form.status = val
		},
		submit() {
			this.$refs['ruleForm'].validate((valid) => {
				if (valid) {
					console.log(this.form);
					// 审核通过
					if (this.form.status == 1) {
						withdrawalPass(this.editId).then(res => {
							this.$emit('getList')
							this.dialogVisible = false
						})
					} else {
						if (this.form.remark == '') {
							this.$message({
								message: '请填写拒绝原因',
								type: 'error'
							})
							return
						} else {
							// 审核拒绝
							withdrawalRefuse({ id: this.editId, remark: this.form.remark }).then(res => {
								this.$emit('getList',true)
								this.dialogVisible = false
							})
						}

					}
				} else {
					this.$message({
						message: '请检查表单错误',
						type: 'error'
					})
					return false
				}
			})
		}
	}
}
</script>

<style lang="less" scoped></style>
